<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
<div>
<input type="text" id="i1" v-model="n1">
<input type="text" id="i2" v-model="n2">
<input type="button" value="加" @click="f(1)">
<input type="button" value="减" @click="f(2)">
<input type="button" value="乘" @click="f(3)">
<input type="button" value="除" @click="f(4)">
<div v-text="m"></div>
</div>
<script src="js/vue.min.js"></script>
<script>
  let v = new Vue({
    el:"body>div",
    data:{
      n1:"",
      n2:"",
      m:"结果:",
    },
    methods: {
      f(x){
        if (isNaN(v.n1)||isNaN(v.n2)){
        v.m="输入错误"
          return;
        }
        switch (x){
          case 1:
            v.m = "结果:"+ (i1.value*1+i2.value*1);
            break;
          case 2:
            v.m = "结果:"+ (i1.value-i2.value);
            break;
          case 3:
            v.m = "结果:"+ (i1.value*i2.value);
            break;
          case 4:
            v.m = "结果:"+ (i1.value/i2.value);
            break;
        }
      }
    }
  })
</script>
</body>
</html>